<template>
  <div id="app">
    <router-view></router-view>
  </div>
</template>

<script>
// import storage from "./storage";
export default {
  name: "app",
  components: {},
  data() {
    return {
      res: {}
    };
  },
  mounted() {
    if (this.$cookie.get("userId")) {
      this.getUser();
      this.getCartCount();
    }
  },
  methods: {
    // 方法直接从cookie读数据
    getUser() {
      // 给定res一个默认值：
      this.axios.get("/user").then((res = {}) => {
        // 截获用户cookie信息然后保存到VUEX
        // store.commit('saveUserName',res.username);
        if (res) {
          this.$store.dispatch("saveUserName", res.username);
        }
      });
    },
    getCartCount() {
      // 给定res一个默认值：
      this.axios.get("/carts/products/sum").then((res = 0) => {
        // 截获购物车信息然后保存到VUEX
        this.$store.dispatch("saveCartCount", res);
      });
    }
  }
};
</script>

<style lang="less">
@import "./assets/less/reset.less";
@import "./assets/less/modal.less";
@import "./assets/less/button.less";
@import "./assets/iconfont/iconfont.css";
</style>
